package io.github.jesse205.dragdrop.pro.extensions

import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.view.View
import io.github.jesse205.dragdrop.pro.app.DragDropApp

/**
 * 中转站应用
 * */
val Context.thisApp get() = applicationContext as DragDropApp

/**
 * 布局方向是否为从右到左
 * */
val Context.isRtl get() = resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL

val Context.isNightMode get() = resources.configuration.run { (uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES }

/**
 * 获取主题颜色值
 * @param resAttrId Attr 资源ID
 * */
fun Context.getThemeColor(resAttrId: Int): Int {
    val typedArray = obtainStyledAttributes(intArrayOf(resAttrId))
    val color = typedArray.getColor(0, Color.RED)
    typedArray.recycle()
    return color
}

/**
 * 获取主题布尔值
 * @param resAttrId Attr 资源ID
 * */
fun Context.getThemeBoolean(resAttrId: Int): Boolean {
    val typedArray = obtainStyledAttributes(intArrayOf(resAttrId))
    val boolean = typedArray.getBoolean(0, false)
    typedArray.recycle()
    return boolean
}